import {Component, EventEmitter, Input, OnDestroy, OnInit, Output} from "@angular/core";
import {CommService} from "../comm-service";
import {SharedService} from "../shared-service";
import {LocalStorageService} from "../local-storage-service";
import {MyhttpService} from "../myhttp.service";

declare var $: any

@Component({
  template: `
    <div class="bmskdlb comp" [style.width]="compw" [style.height]="comph" [style.top]="topv"
         [style.left]="leftv">
      <div class="content">
        <div class="title">
          <div class="title_text">{{comptitle}}</div>
        </div>
        <div class="body">
          <div class="input_form">
            <input type="text" placeholder="保密室名称/考点名称/试卷包名称" name="cxtj" [(ngModel)]="s_obj.cxtj"/>
            <span class="search-icon" (click)="searchDone(1,'')"><i class="fa fa-search"></i></span>
          </div>
          <div class="formgroup">
            <span *ngFor="let item of sdatalist" class="sdataitem"
                  [style.backgroundColor]="item.active?'#056BFE':'#b4b4b4'"
                  (click)="searchDone(2,item)">{{item.name}}</span>
          </div>
          <div class="treeroom fzroom iecrollkf chromescrollkf">
            <!--<div id="tree"></div>-->
            <div class="fzitem" *ngFor="let fzobj of fzList">
              <div class="icon_expand" (click)="toggleFzexpand(fzobj)">
                <span *ngIf="fzobj.expand"><i class="fa fa-minus-square-o"></i></span>
                <span *ngIf="!fzobj.expand"> <i class="fa fa-plus-square-o"></i></span>
              </div>
              <div class="icon_checkbox">
                <label class="mt-checkbox">
                  <input type="checkbox" name="fzcheck" [checked]="fzobj.checked" (click)="checkedToggle(1,fzobj)"/>
                  <span></span>
                </label>
              </div>
              <div class="icon_n"><span class="glyphicon glyphicon-home"></span></div>
              <span [style.color]="fzobj.actived?'#0FBEF0':'#000'" [title]="fzobj.li_attr.title"
                    (click)="checkedToggle(3,fzobj)">{{fzobj.text}}</span>
              <div class="fzchildren" *ngIf="fzobj.expand&&fzobj.children.length">
                <div class="fzitem" *ngFor="let bmsobj of fzobj.children">
                  <div class="icon_expand" (click)="toggleFzexpand(bmsobj)">
                    <span *ngIf="bmsobj.expand"><i class="fa fa-minus-square-o"></i></span>
                    <span *ngIf="!bmsobj.expand"> <i class="fa fa-plus-square-o"></i></span>
                  </div>
                  <div class="icon_checkbox">
                    <label class="mt-checkbox">
                      <input type="checkbox" name="bmscheck" [checked]="bmsobj.checked"
                             (click)="checkedToggle(1,bmsobj)"/>
                      <span></span>
                    </label>
                  </div>
                  <div class="icon_n"><i class="fa fa-shield"></i></div>
                  <span [style.color]="bmsobj.actived?'#0FBEF0':'#000'"
                        [title]="bmsobj.li_attr.title" (click)="checkedToggle(3,bmsobj)">{{bmsobj.text}}</span>
                  <div class="fzchildren" *ngIf="bmsobj.expand&&bmsobj.children.length">
                    <div class="fzitem" *ngFor="let kdobj of bmsobj.children">
                      <div class="icon_expand" (click)="toggleFzexpand(kdobj)">
                        <span *ngIf="kdobj.expand"><i class="fa fa-minus-square-o"></i></span>
                        <span *ngIf="!kdobj.expand"> <i class="fa fa-plus-square-o"></i></span>
                      </div>
                      <div class="icon_checkbox">
                        <label class="mt-checkbox">
                          <input type="checkbox" name="kdcheck" [checked]="kdobj.checked"
                                 (click)="checkedToggle(1,kdobj)"/>
                          <span></span>
                        </label>
                      </div>
                      <div class="icon_n"><i class="fa fa-university"></i></div>
                      <span [style.color]="kdobj.actived?'#0FBEF0':'#000'"
                            [title]="kdobj.li_attr.title" (click)="checkedToggle(3,kdobj)">{{kdobj.text}}</span>
                      <div class="fzchildren_leaf" *ngIf="kdobj.expand&&kdobj.children.length">
                        <div class="fzitem" *ngFor="let bqobj of kdobj.children">
                          <div class="icon_checkbox">
                            <label class="mt-checkbox">
                              <input type="checkbox" name="bqcheck" [checked]="bqobj.checked"
                                     (click)="checkedToggle(2,bqobj)"/>
                              <span></span>
                            </label>
                          </div>
                          <div class="icon_n"><i class="fa fa-microchip"></i></div>
                          <span [style.color]="bqobj.actived?'#0FBEF0':'#000'"
                                [title]="bqobj.li_attr.title" (click)="checkedToggle(3,bqobj)">{{bqobj.text}}</span>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  `,
  styles: [
    ".bmskdlb{position:absolute;background-color:#fff;border:5px solid #ccc;}",
    ".content{width: calc(100%);height: calc(100%);}",
    ".content>.title{position: relative;width: 100%;height: auto;padding: 10px; border-bottom: 1px solid #ccc; color: rgb(138 143 151);}",
    ".title>.title_text{height: 15px;line-height: 15px;font-size: 15px;  width: auto;border-left: 5px solid #1477F3;padding-left: 10px}",
    ".content>.body{position: relative;width: 100%;height: calc(100% - 24px);padding: 10px 10px}",
    ".input_form{width: 100%;height: 35px;border: 1px solid #D7D7D7;}",
    ".input_form>input{border: none;height: 32px;line-height: 32px; width: calc(100% - 40px);padding: 0px 10px}",
    ".input_form>.search-icon{display: inline-block; width: 40px;text-align: center;font-size: 20px;cursor: pointer;color: #0051C4}",
    ".formgroup{width: 100%;height: 30px;margin-top: 10px}",
    ".sdataitem{display: inline-block;margin-right: 15px;width: auto;height: 20px;padding: 0px 5px;cursor: pointer;color: #ffffff}",
    // ".treeroom{width: calc(100% - 17px); height: 180px;margin-top: 10px; overflow-y: auto}",

    //list
    ".fztitle{}",
    ".fzroom{width: calc(100% - 17px);height: 490px;padding-left: 20px; overflow-y: auto}",
    ".fzitem{width: 100%;padding: 5px 0px}",
    // one fzitem
    ".icon_expand{float: left;padding-right: 10px;cursor: pointer;}", /*展开 折叠符号*/
    ".icon_checkbox{float:left;}", /*分组的复选框*/
    ".icon_n{display: inline-block;padding-right: 5px;color: #0FBEF0}", /*分组图标*/
    // onefz 下内容
    ".fzchildren{width: 100%;height: auto;padding-left: 25px}",
    ".fzchildren_leaf{width: 100%;height: auto;padding-left: 43px}"


  ]
})
export class BmskdBmskdlbComponent implements OnInit, OnDestroy {
  compw: string = "0px";
  comph: string = "0px";
  topv: string = "0px";
  leftv: string = "0px";
  comptitle: string = "保密室及考点列表";
  frompage: string;
  sdatalist: any[] = [{
    key: "",
    name: "全天",
    active: true
  }, {
    key: "am",
    name: "上午",
    active: false
  }, {
    key: "pm",
    name: "下午",
    active: false
  }];
  s_obj: any = {
    ksgljgid: "",
    ksjhbh: "",
    ksjd: "", // 考试阶段 am 上午；pm 下午
    cxtj: ''
  };
  fzList: any[] = [];

  activebqobj: any;
  kdbhs: string[] = [];
  bqcheckedList: any[] = [];
  bmskdcheckedList: any[] = [];
  activebmsOrkd: any;

  /**
   *
   * @param {number} n
   * 1---搜索按钮
   * 2---时间搜索
   * @param sdata
   */
  searchDone(n: number, sdata: any): void {
    switch (n) {
      case 1:
        break;
      case 2:
        this.sdatalist.forEach((item) => {
          item.active = false;
        });
        sdata.active = true;
        this.s_obj.ksjd = sdata.key;
        break;
    }
    this.searching();
  }

  /**
   * 搜索 保密室+考点
   */
  searching(): void {
    if (!this.s_obj.ksgljgid || !this.s_obj.ksjhbh) {
      return
    }
    this.sharedService.emitChange({
      actiontype: "activeNode",
      data: {
        activebqobj: null,
        kdbhs: [],
        bqlist: [],
        bmskdlist: []
      }
    });

    const url = "sjgz/zsymbmsjkd/bmsjkdlb";
    this.itservice.kwPtPost(url, this.s_obj).subscribe(resp => {
      this.commservice.handResponse("get", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            const bmsjkdListv = resp.bmsjkdList ? resp.bmsjkdList : [];
            if (!bmsjkdListv.length) {
              this.fzList.length = 0;
              this.sharedService.emitChange({
                actiontype: "bqzttj",
                data: {
                  bqlist: []
                }
              });
              return
            }
            //this.initTree(bmsjkdListv);
            this.handData(bmsjkdListv);
          }
        }
      });
    });
  }

  /**
   * 处理分组数据
   * @param data
   */
  handData(data: any): void {
    const search_bqlist: any[] = [];
    const treeData = data.map((obj) => {
      const fzmcv = obj.fzmc;
      const bmsfzListv = obj.bmsfzList ? obj.bmsfzList : [];
      const bmsfzList_formatter = bmsfzListv.map((bmsobj) => {
        const bmsmcv = bmsobj.bmsmc;
        const bmsbhv = bmsobj.bmsbh;
        const kdfzListv = bmsobj.kdfzList ? bmsobj.kdfzList : [];
        const kdfzList_fomatter = kdfzListv.map((kdobj) => {
          const kdmcv = kdobj.kdmc;
          const kdbhv = kdobj.kdbh;
          const kdsjbListv = kdobj.kdsjbList ? kdobj.kdsjbList : [];
          const kdsjbList_formatter = kdsjbListv.map((bqobj) => {
            search_bqlist.push(bqobj);
            return {
              id: bqobj.dzbqid,
              type: "bq",
              text: bqobj.sjbmc,
              data: {
                sjbbh: bqobj.sjbbh,
                sjbmc: bqobj.sjbmc,
                zxzt: bqobj.zxzt
              },
              li_attr: {
                title: bqobj.sjbmc
              },
              actived: false,
              checked: false,
            }
          });
          return {
            id: kdbhv,
            type: "bzhkd",
            text: kdmcv,
            data: {},
            li_attr: {
              title: kdmcv
            },
            expand: false,
            actived: false,
            checked: false,
            children: kdsjbList_formatter
          };
        });
        return {
          id: bmsbhv,
          type: "bms",
          text: bmsmcv,
          data: {},
          li_attr: {
            title: bmsmcv
          },
          expand: false,
          actived: false,
          checked: false,
          children: kdfzList_fomatter
        }
      });
      return {
        type: "ksgljg",
        text: fzmcv,
        data: {},
        li_attr: {
          title: fzmcv
        },
        expand: false,
        actived: false,
        checked: false,
        children: bmsfzList_formatter
      }
    });
    this.fzList = treeData;
    console.log("fzlist", treeData);
    this.sharedService.emitChange({
      actiontype: "bqzttj",
      data: {
        bqlist: search_bqlist
      }
    });
  }

  /**
   * 分组展开/隐藏切换
   * @param fzobj
   */
  toggleFzexpand(fzobj: any): void {
    fzobj.expand = !fzobj.expand;
  }


  /**
   * 勾选控制
   * @param {number} type
   * 1--某个分组/保密室/考点  全选/取消全选--下处理
   * 2--某个标签      勾选/取消勾选
   * 3---某个 分组/保密室/考点/标签     高亮/取消高亮
   */
  checkedToggle(type: number, obj: any): void {
    switch (type) {
      case 1: {
        const nodeid = obj.id;
        const nodechecked = obj.checked;
        const nodetype = obj.type;
        const nodechildren = obj.children;
        if (nodetype == "ksgljg") {
          const itksgljg_bmslist = nodechildren;  //  考试管理机构下的     保密室节点列表
          //(1) 考试管理机构下  节点的  勾选处理  高亮处理
          itksgljg_bmslist.forEach((bmsobj) => {
            if (nodechecked) {
              bmsobj.checked = false;
              this.bmskdcheckedList = this.bmskdcheckedList.filter((item) => {
                return bmsobj.id != item.id;
              });
            } else {
              bmsobj.checked = true;
              this.bmskdcheckedList.push(bmsobj);
            }
            // 保密室下    考点节点列表
            const kdlist = bmsobj.children ? bmsobj.children : [];
            kdlist.forEach((kdobj) => {
              if (nodechecked) {
                kdobj.checked = false;
                this.bmskdcheckedList = this.bmskdcheckedList.filter((item) => {
                  return kdobj.id != item.id;
                });
                this.kdbhs = this.kdbhs.filter((kdbh) => {
                  return kdobj.id != kdbh;
                })
              } else {
                kdobj.checked = true;
                this.bmskdcheckedList.push(kdobj);
                this.kdbhs.push(kdobj.id);
              }
              // 考点下    标签节点处理
              const bqlist = kdobj.children ? kdobj.children : [];
              bqlist.forEach((bqobj) => {
                if (nodechecked) {
                  bqobj.checked = false;
                  bqobj.actived = false;  // 不勾选的标签一定不能高亮
                  this.bqcheckedList = this.bqcheckedList.filter((item) => {
                    return bqobj.id != item.id;
                  });
                  //取消高亮
                  if (this.activebqobj) {
                    if (this.activebqobj.id == bqobj.id) {
                      // 高亮的终端在这个取消 分组下
                      this.activebqobj = null;
                    }
                  }
                } else {
                  bqobj.checked = true;
                  this.bqcheckedList.push(bqobj);
                }
              });
            });
          });
          // (2)考试管理机构节点自己的  勾选状态切换
          if (nodechecked) {
            obj.checked = false;
          } else {
            obj.checked = true;
          }
        } else if (nodetype == "bms") {
          const itbms_kdlist = nodechildren;  //  保密室下     考点节点列表
          //(1)  保密室下  节点的 勾选状态  高亮状态处理
          itbms_kdlist.forEach((kdobj) => {
            if (nodechecked) {
              kdobj.checked = false;
              this.bmskdcheckedList = this.bmskdcheckedList.filter((item) => {
                return kdobj.id != item.id;
              });
              this.kdbhs = this.kdbhs.filter((kdbh) => {
                return kdobj.id != kdbh;
              })
            } else {
              kdobj.checked = true;
              this.bmskdcheckedList.push(kdobj);
              this.kdbhs.push(kdobj.id);
            }
            // 考点下    标签节点处理
            const bqlist = kdobj.children ? kdobj.children : [];
            bqlist.forEach((bqobj) => {
              if (nodechecked) {
                bqobj.checked = false;
                bqobj.actived = false;  // 不勾选的标签一定不能高亮
                this.bqcheckedList = this.bqcheckedList.filter((item) => {
                  return bqobj.id != item.id;
                });
                //取消高亮
                if (this.activebqobj) {
                  if (this.activebqobj.id == bqobj.id) {
                    // 高亮的终端在这个取消 分组下
                    this.activebqobj = null;
                  }
                }
              } else {
                bqobj.checked = true;
                this.bqcheckedList.push(bqobj);
              }
            });
          });

          //(2) 保密室节点自己的   勾选状态处理
          if (nodechecked) {
            obj.checked = false;
            this.bmskdcheckedList = this.bmskdcheckedList.filter((item) => {
              return obj.id != item.id;
            });
          } else {
            obj.checked = true;
            this.bmskdcheckedList.push(obj);
          }
        } else if (nodetype == "bzhkd") {
          const itkd_bqlist = nodechildren;  // 考点下的 标签列表
          //(1) 考点下   节点的勾选状态    高亮状态处理
          itkd_bqlist.forEach((bqobj) => {
            if (nodechecked) {
              bqobj.checked = false;
              bqobj.actived = false;  // 不勾选的标签一定不能高亮
              this.bqcheckedList = this.bqcheckedList.filter((item) => {
                return bqobj.id != item.id;
              });
              //取消高亮
              if (this.activebqobj) {
                if (this.activebqobj.id == bqobj.id) {
                  // 高亮的终端在这个取消 分组下
                  this.activebqobj = null;
                }
              }
            } else {
              bqobj.checked = true;
              this.bqcheckedList.push(bqobj);
            }
          });
          //(2) 考点节点自己的  勾选状态处理
          if (nodechecked) {
            obj.checked = false;
            this.bmskdcheckedList = this.bmskdcheckedList.filter((item) => {
              return obj.id != item.id;
            });
            this.kdbhs = this.kdbhs.filter((kdbh) => {
              return obj.id != kdbh;
            })
          } else {
            obj.checked = true;
            this.bmskdcheckedList.push(obj);
            this.kdbhs.push(obj.id);
          }
        }
      }
        break;
      case 2: {
        // 原则 ： 标签取消选中，一定不能高亮
        // 取消选中的时候 需要  判断此是否是高亮，是高亮，取消高亮
        const bqid = obj.id;
        const bqchecked = obj.checked;
        const bqactived = obj.actived;
        if (bqchecked) {
          obj.checked = false;
          this.bqcheckedList = this.bqcheckedList.filter((bqobj) => {
            return bqid != bqobj.id;
          });
          if (bqactived) {
            obj.actived = false;
            this.activebqobj = null;
          }
        } else {
          obj.checked = true;
          this.bqcheckedList.push(Object.assign({}, obj));
        }
      }
        break;
      case 3: {
        //原则：  标签高亮  一定要选中
        //（1） 高亮还原 （2）设置此节点高亮  （3）如果是标签，高亮了，需要判断是否勾选，没勾选一定要设置勾选
        const nodeid = obj.id;
        const nodechecked = obj.checked;
        const nodetype = obj.type;
        const nodeactived = obj.actived;
        this.fzList.forEach((ksgljgobj) => {
          if (ksgljgobj.actived) {
            ksgljgobj.actived = false;
          }
          const it_bmslist = ksgljgobj.children; // 保密室列表
          it_bmslist.forEach((bmsobj) => {
            if (bmsobj.actived) {
              bmsobj.actived = false;
            }
            const it_kdlist = bmsobj.children;  // 考点列表
            it_kdlist.forEach((kdobj) => {
              if (kdobj.actived) {
                kdobj.actived = false;
              }
              const it_bqlist = kdobj.children;  // 标签列表
              it_bqlist.forEach((bqobj) => {
                if (bqobj.actived) {
                  bqobj.actived = false;
                }
              });
            });
          });
        });
        obj.actived = true; //设置此节点高亮
        if (nodetype == "bq") {
          this.activebqobj = obj;
          if (!nodechecked) {
            obj.checked = true;
            this.bqcheckedList.push(Object.assign({}, obj));
          }
        } else {
          this.activebmsOrkd = obj;
        }
      }

        break;
    }

    this.bqcheckedList = this.commservice.fliterobjRepeat(this.bqcheckedList, "id");
    this.bmskdcheckedList = this.commservice.fliterobjRepeat(this.bmskdcheckedList, "id");
    this.kdbhs = this.commservice.fliterRepeat(this.kdbhs);
    this.commservice.log("bqcheckedList", this.bqcheckedList);
    this.commservice.log("bmskdcheckedList", this.bmskdcheckedList);
    this.commservice.log("kdbhs", this.kdbhs);
    this.commservice.log("activebq", this.activebqobj);
    this.commservice.log("activebmskd", this.activebmsOrkd);
    //广播，选中的终端列表，和当前高亮的终端对象
    this.sharedService.emitChange({
      actiontype: "activeNode",
      data: {
        activebqobj: this.activebqobj,
        kdbhs: this.kdbhs,
        bqlist: this.bqcheckedList,
        bmskdlist: this.bmskdcheckedList,
        activebmsOrkd: this.activebmsOrkd
      }
    });
  }

  /**
   * 组建 树形结构
   * @param baseList
   */
  initTree(baseList: any): void {
    const treeData = baseList.map((obj) => {
      const fzmcv = obj.fzmc;
      const bmsfzListv = obj.bmsfzList ? obj.bmsfzList : [];
      const bmsfzList_formatter = bmsfzListv.map((bmsobj) => {
        const bmsmcv = bmsobj.bmsmc;
        const bmsbhv = bmsobj.bmsbh;
        const kdfzListv = bmsobj.kdfzList ? bmsobj.kdfzList : [];
        const kdfzList_fomatter = kdfzListv.map((kdobj) => {
          const kdmcv = kdobj.kdmc;
          const kdbhv = kdobj.kdbh;
          const kdsjbListv = kdobj.kdsjbList ? kdobj.kdsjbList : [];
          const kdsjbList_formatter = kdsjbListv.map((bqobj) => {
            return {
              id: bqobj.dzbqid,
              type: "bq",
              text: bqobj.sjbmc,
              data: {
                sjbbh: bqobj.sjbbh,
                sjbmc: bqobj.sjbmc,
                zxzt: bqobj.zxzt
              },
              li_attr: {
                title: bqobj.sjbmc
              },
            }
          });
          return {
            id: kdbhv,
            type: "bzhkd",
            text: kdmcv,
            data: {},
            li_attr: {
              title: kdmcv
            },
            children: kdsjbList_formatter
          };
        });
        return {
          id: bmsbhv,
          type: "bms",
          text: bmsmcv,
          data: {},
          li_attr: {
            title: bmsmcv
          },
          children: kdfzList_fomatter
        }
      });
      return {
        id: "",
        type: "ksgljg",
        text: fzmcv,
        data: {},
        li_attr: {
          title: fzmcv
        },
        children: bmsfzList_formatter
      }
    });
    const that = this;
    $("#tree").jstree({
      "core": {
        "themes": {
          name: "default",
          url: true,
          dir: "assets/jstreethemes",
        },
        data: treeData
      },
      "plugins": ["types", "checkbox"],
      "checkbox": {
        "keep_selected_style": true,// 保持选中样式 true为保持，false为不保存，样式不影响功能
        "three_state": true, //父子节点关联，true为关联，false为不关联
        "whole_node": false, //复选框与节点关联, true 为关联 false为不关联
        "tie_selection": false  //此设置控制复选框是否绑定到常规树选择或复选框插件维护的内部数组。默认为 true，
      },
      "types": {
        "ksgljg": {
          "icon": "glyphicon glyphicon-home"
        },
        "bzhkd": {
          "icon": "fa fa-university"
        },
        "bms": {
          "icon": "fa fa-shield"
        },
        "bq": {
          "icon": "fa fa-microchip"
        }
      }
    }).on("activate_node.jstree", function (node, selected) {
      const nodeType = selected.node.type; // bms    bzhkd    bq
      const nodeid = selected.node.id;
      const nodetext = selected.node.text;
      if (nodeType == "ksgljg") {
        return
      }
      const kdbhs: any[] = [];// 高亮节点的 kdbhs
      if (nodeType == "bzhkd") {
        kdbhs.push(nodeid);
      } else if (nodeType == "bms") {
        const children_kdlist = $("#tree").jstree("get_json", selected.node).children;
        children_kdlist.forEach((kdnode) => {
          kdbhs.push(kdnode.id);
        });
      } else if (nodeType == "bq") {
        that.activebqobj = selected.node;
        // 高亮一定选中

      }
      that.sharedService.emitChange({
        actiontype: "activeNode111111111111",
        data: {
          nodetype: nodeType, // bms    bzhkd    bq
          nodeid: nodeid,
          nodetext: nodetext,
          activebqobj: that.activebqobj,
          kdbhs: kdbhs
        }
      });
    }).on("check_node.jstree", function (e, selected) {
      // 复选框选中 仅当复选框设置中的tie_selection为false时有效
      const nodeType = selected.node.type; // bms    bzhkd    bq
      const nodeid = selected.node.id;
      const nodetext = selected.node.text;
      // 获取所有选中节点，刷选出来，bms  和  bzhkd，在右侧地图上显示marker
      const checkedList = $("#tree").jstree("get_checked", true);
      const checkedFilter_kdbms = checkedList.filter((node) => {
        return ["bms", "bzhkd"].indexOf(node.type) != -1;
      });
      const checkedFilter_bq = checkedList.filter((node) => {
        return node.type == "bq";
      });
      that.bmskdcheckedList = checkedFilter_kdbms;
      that.bqcheckedList = checkedFilter_bq;
      that.sharedService.emitChange({
        actiontype: "checkednode1111111111111",
        data: {
          bqlist: that.bqcheckedList,
          bmskdlist: that.bmskdcheckedList
        }
      });
    }).on("uncheck_node.jstree", function (node, selected, event) {
      //  复选框选中 仅当复选框设置中的tie_selection为false时有效
      const nodeType = selected.node.type; // bms    bzhkd    bq
      const nodeid = selected.node.id;
      const nodetext = selected.node.text;
      // 只管勾选的节点，和其下的节点
      if (nodeType == "bq") {
        //## 处理 考点/保密室
        //##处理实时电子标签
        that.bqcheckedList = that.bqcheckedList.filter((bqobj) => {
          return nodeid != bqobj.id;
        });
      } else if (nodeType == "bzhkd") {
        //###处理 考点/保密室
        that.bmskdcheckedList = that.bmskdcheckedList.filter((kdobj) => {
          return nodeid != kdobj.id;
        });
        //###处理实时电子标签
        const children_bqlist = $("#tree").jstree("get_json", selected.node).children;
        const children_bqidlist = children_bqlist.map((bqnode) => {
          return bqnode.id;
        });
        that.bqcheckedList = that.bqcheckedList.filter((bqobj) => {
          return children_bqidlist.indexOf(bqobj.id) == -1;
        });
      } else if (nodeType == "bms") {
        //#### 处理 考点/保密室
        that.bmskdcheckedList = that.bmskdcheckedList.filter((bmsobj) => {
          return nodeid != bmsobj.id;
        });
        const children_kdlist = $("#tree").jstree("get_json", selected.node).children;
        children_kdlist.forEach((kdnode) => {
          that.bmskdcheckedList = that.bmskdcheckedList.filter((kdobj) => {
            return kdnode.id != kdobj.id;
          });
          //########处理实时电子标签
          const children_bqlist = $("#tree").jstree("get_json", node).children;
          const children_bqidlist = children_bqlist.map((bqnode) => {
            return bqnode.id;
          });
          that.bqcheckedList = that.bqcheckedList.filter((bqobj) => {
            return children_bqidlist.indexOf(bqobj.id) == -1;
          });
        });
      } else if (nodeType == "ksgljg") {
        //####### 处理 考点/保密室
        const children_bmslist = $("#tree").jstree("get_json", selected.node).children;
        children_bmslist.forEach((bmsnode) => {
          that.bmskdcheckedList = that.bmskdcheckedList.filter((bmsobj) => {
            return bmsnode.id != bmsobj.id;
          });
          const node = $("#tree").jstree("get_node", bmsnode.id); // 保密室节点
          const children_kdlist = $("#tree").jstree("get_json", node).children;
          children_kdlist.forEach((kdnode) => {
            that.bmskdcheckedList = that.bmskdcheckedList.filter((kdobj) => {
              return kdnode.id != kdobj.id;
            });
            const node = $("#tree").jstree("get_node", kdnode.id); // 考点节点
            //########处理实时电子标签
            const children_bqlist = $("#tree").jstree("get_json", node).children;
            const children_bqidlist = children_bqlist.map((bqnode) => {
              return bqnode.id;
            });
            that.bqcheckedList = that.bqcheckedList.filter((bqobj) => {
              return children_bqidlist.indexOf(bqobj.id) == -1;
            });
          });
        });
      }
      that.sharedService.emitChange({
        actiontype: "checkednode1111111111111",
        data: {
          bqlist: that.bqcheckedList,
          bmskdlist: that.bmskdcheckedList
        }
      });
    });
  }


  /**
   * 组件在 显示面板中的位置+ 大小
   */
  initcompPositionSize_ctrshow(): void {
    // 位置 大小
    this.compw = this.o.compw + "px";
    this.comph = this.o.comph + "px";
    this.topv = this.o.topv + "px";
    this.leftv = this.o.leftv + "px";
    // 显示
    this.frompage = this.o.frompage;
    if (this.frompage === "bmskd") {
      this.searching();
    }
  }


  @Input() o: any;
  @Output() outhander: EventEmitter<any> = new EventEmitter();

  constructor(private commservice: CommService,
              private localStorageService: LocalStorageService,
              private itservice: MyhttpService,
              private sharedService: SharedService) {
    this.sharedService.changeEmitted$.subscribe(resp => {
      const actiontype = resp.actiontype;
      const datav = resp.data;
      if (actiontype == "toggleActiveBq") {
        const activebqobj = datav.activebqobj;
        const activebqId = activebqobj ? activebqobj.id : "";
        this.fzList.forEach((ksgljgobj) => {
          if (ksgljgobj.actived) {
            ksgljgobj.actived = false;
          }
          const bmslist = ksgljgobj.children;
          bmslist.forEach((bsmobj) => {
            if (bsmobj.actived) {
              bsmobj.actived = false;
            }
            const kdlist = bsmobj.children;
            kdlist.forEach((kdobj) => {
              if (kdobj.actived) {
                kdobj.actived = false;
              }
              const bqlist = kdobj.children;
              bqlist.forEach((bqobj) => {
                if (bqobj.id == activebqId) {
                  bqobj.actived = true;
                } else {
                  bqobj.actived = false;
                }
              });
            });
          });
        });
      }
    });
  }

  ngOnInit() {
    this.commservice.log("-- 【 compkey=bmskdlb 】--被父组件动态加载 init....", this.o);
    this.s_obj.ksjhbh = this.localStorageService.get("hksjh");
    this.commservice.getUserinfo((obj) => {
      this.s_obj.ksgljgid = obj.csid;
      this.initcompPositionSize_ctrshow();
    });
  }

  ngOnDestroy() {

  }

}
